package com.api.gbhg.daiyanlu.Dao;

import weaver.conn.RecordSet;
/**
 * 非独立核算单位财务预算核批
 * Mr.dyl
 */
public class FoBudgetProcessDao {
    public static RecordSet getMainTable(Integer pageNum,Integer pageSize,int nd,String dw,boolean state,Integer hsdw){
        RecordSet rs = new RecordSet();
        StringBuilder sql = new StringBuilder();
        if (state){
            if(dw.equals("2"))
                sql.append("select  xmmin,yszje,cjsj from uf_jingfei_version where ysnd = "+nd+" and lcztz = 3 and sfwdlhsdw = "+hsdw+" ");
            else
                sql.append("select  xmmin,yszje,cjsj from uf_jingfei_version where ysnd = "+nd+" and sbdw in ("+dw+") and lcztz = 3 and sfwdlhsdw = "+hsdw+" ");
        }else{
            if(dw.equals("2"))
                sql.append("select  xmmin,yszje,cjsj from uf_jingfei_version where ysnd = "+nd+"  and lcztz != 3 and sfwdlhsdw = "+hsdw+" ");
            else
                sql.append("select  xmmin,yszje,cjsj from uf_jingfei_version where ysnd = "+nd+" and sbdw in ("+dw+")  and lcztz != 3 and sfwdlhsdw = "+hsdw+" ");
        }
        pageNum=(pageNum-1)*pageSize;
        if("sqlserver".equals(rs.getDBType())){
            sql.append(" order by requestId offset "+pageNum+" rows fetch next "+pageSize+" rows only");
        }else if("mysql".equals(rs.getDBType())){
            sql.append(" LIMIT "+pageNum+","+pageSize+"");
        }
        rs.executeQuery(sql.toString());
        return rs;
    }

    //获取数据条数
    public static int getMainTableCount(int nd,String dw,boolean state,Integer hsdw){
        RecordSet rs = new RecordSet();
        String sql ;
        if (state) {
            if (dw.equals("2"))
                sql = "select count(requestId) cut from uf_jingfei_version where ysnd = " + nd + " and lcztz = 3 and sfwdlhsdw = " + hsdw + " ";
            else
                sql = "select count(requestId) cut from uf_jingfei_version where ysnd = " + nd + " and sbdw in (" + dw + ") and lcztz = 3 and sfwdlhsdw = " + hsdw + " ";
        }else{
            if (dw.equals("2"))
                sql = "select count(requestId) cut from uf_jingfei_version where ysnd = " + nd + " and lcztz != 3 and sfwdlhsdw = " + hsdw + " ";
            else
                sql = "select count(requestId) cut from uf_jingfei_version where ysnd = " + nd + " and sbdw in (" + dw + ") and lcztz != 3 and sfwdlhsdw = " + hsdw + " ";
        }
        rs.executeQuery(sql);
        rs.next();
        return rs.getInt("cut");
    }

}
